package cn.itcast.customview.Actrvity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import cn.itcast.customview.Bean.Tooles;
import cn.itcast.customview.R;

import static cn.itcast.customview.Bean.Tooles.hideView;

public class YouKuActivity extends AppCompatActivity implements View.OnClickListener {

     private ImageView icon_home,channel1,channel2;
     private RelativeLayout BangYuan,WaIer,WaIer2;
    /*
     * 是否显示第一圆环
     * true:显示
     * false:隐藏
     * */
    private boolean isShowLevel1=true;
    /*
     * 是否显示第二圆环
     * true:显示
     * false:隐藏
     * */
    private boolean isShowLevel2=true;
     /*
     * 是否显示第三圆环
     * true:显示
     * false:隐藏
     * */
     private boolean isShowLevel3=true;
     private Tooles Toole;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_you_ku);
        icon_home=(ImageView) findViewById(R.id.icon_home);
        channel1=(ImageView)findViewById(R.id.channel1);
        channel2=(ImageView)findViewById(R.id.channel2);
        BangYuan=(RelativeLayout)findViewById(R.id.BangYuan);
        WaIer=(RelativeLayout)findViewById(R.id.WaIer);
        WaIer2=(RelativeLayout)findViewById(R.id.WaIer2);

        icon_home.setOnClickListener(this);
        channel1.setOnClickListener(this);
//        BangYuan.setOnClickListener(this);
//        WaIer.setOnClickListener(this);
//        WaIer2.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
//            case R.id.BangYuan:
//                Toast.makeText(YouKuActivity.this,"我是第一层",Toast.LENGTH_SHORT).show();
//                break;
//
//            case R.id.WaIer:
//                Toast.makeText(YouKuActivity.this,"我是第二层",Toast.LENGTH_SHORT).show();
//                break;
//            case R.id.WaIer2:
//                Toast.makeText(YouKuActivity.this,"我是第三层",Toast.LENGTH_SHORT).show();
//                break;

            case R.id.icon_home://home
           //如果三级菜单和二级菜单是显示的，都设置隐藏
                if (isShowLevel2){
                    //隐藏二级菜单
                    isShowLevel2=false;
                    Tooles.hideView(WaIer);
                    if (isShowLevel3){
                        //隐藏三级菜单

                        isShowLevel3=false;
                        Tooles.hideView(WaIer2,200);
                    }
                }else {
                    //显示二级菜单
                    isShowLevel2=true;
                    Tooles.showView(WaIer);
                }

                break;
            case R.id.channel1://菜单

                if (isShowLevel3){
                    //隐藏
                    isShowLevel3=false;
                    Tooles.hideView(WaIer2);
                }else {
                    //显示
                    isShowLevel3=true;
                    Tooles.showView(WaIer2);
                }

                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode==KeyEvent.KEYCODE_MENU){
         //如果一级，二级，三级菜单是显示的就全部隐藏

            if (isShowLevel1){
                isShowLevel1=false;
                Tooles.hideView(BangYuan);
                if (isShowLevel2){
                    //隐藏二级菜单
                    isShowLevel2=false;
                    Tooles.hideView(WaIer,200);

                    if (isShowLevel3){
                        //隐藏三级菜单
                        isShowLevel3=false;
                        Tooles.hideView(WaIer,400);
                    }
                }

            }else {
                // 如果一级，二级菜单隐藏，就显示
                //显示一级菜单
                isShowLevel1=true;
                Tooles.showView(BangYuan);

                //显示二级菜单
                isShowLevel2=true;
                Tooles.showView(WaIer,200);

            }

            return true;
        }
        return super.onKeyDown(keyCode, event);


    }
}
